package leetcode.每日一题;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/12/6 12:05
 * @description：https://leetcode-cn.com/problems/truncate-sentence/
 */
public class 截断句子 {
    @Test
    public void test() {
        Solution solution = new Solution();
    }

    class Solution {
        public String truncateSentence(String s, int k) {
            String[] strings = s.split(" ");
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < k; i++) {
                builder.append(strings[i]).append(" ");
            }
            return builder.toString().trim();
        }
    }
}
